<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/common/template.xhtml">

	<ui:define name="headSection">

	</ui:define>

	<ui:define name="pageContent">

		<h:form>
			<h:panelGroup>
				<table class="mainTable" style="margin-bottom: 10px;">
					<tr>
						<td><h:outputLabel value="Име">
								<br />
								<h:inputText value="#{aktualiziraneNaSlujitel.searchName}"
									maxlength="50" />
							</h:outputLabel></td>
						<td><h:outputLabel value="Фамилия">
								<br />
								<h:inputText value="#{aktualiziraneNaSlujitel.searchFamily}"
									maxlength="50" />
							</h:outputLabel></td>
						<td>
							<table class="buttonTable">
								<tr>
									<td><h:commandButton value="Търси" class="regButton"
											style="width:80px;height:40px;margin-left:-55px;margin-top: 20px;"
											action="#{aktualiziraneNaSlujitel.searchIt()}" /> <h:commandButton
											value="Изчисти" class="regButton"
											style="width:80px;height:40px;"
											action="#{aktualiziraneNaSlujitel.resetSearch()}" /></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</h:panelGroup>
		</h:form>

		<div id="scroolTable">
			<!-- scroll bar -->
			<h:form>

				<!-- за Калин - избрания ред ще има клас = "selectedRow", неизбраните = "notSelectedRow" -->
				<h:dataTable rows="#{configurationProperties.getPageSize()}"
					value="#{aktualiziraneNaSlujitel.spisukSlujiteli}" first="0"
					var="curr" rowClasses="#{aktualiziraneNaSlujitel.rowStyleClasses}">

					<h:column>
						<f:facet name="header">Име</f:facet>
					#{curr.name}
				</h:column>

					<h:column>
						<f:facet name="header">Фамилия</f:facet>
					#{curr.family}
				</h:column>

					<h:column>
						<f:facet name="header">Населено място</f:facet>
					#{curr.addressCity}
				</h:column>

					<h:column>
						<f:facet name="header">Адрес</f:facet>
					#{curr.addressLine}
				</h:column>

					<h:column>
						<f:facet name="header">Електронна поща</f:facet>
					#{curr.mail}
				</h:column>

					<h:column>
						<f:facet name="header">Телефонен номер</f:facet>
					#{curr.phoneNumber}
				</h:column>

					<h:column>
						<f:facet name="header">Промени</f:facet>
						<h:commandButton
							action="#{aktualiziraneNaSlujitel.selectRow(curr)}"
							value="Промени" 
							class="inTableButton"/>
					</h:column>

					<h:column rendered="#{aktualiziraneNaSlujitel.choosingAllowed}">
						<f:facet name="header">Избери</f:facet>
						<h:commandButton
							action="#{aktualiziraneNaSlujitel.chooseEmployee(curr)}"
							value="Избери" class="inTableButton"/>
					</h:column>

					<f:facet name="footer">

						<!-- предишна страница -->
						<h:commandLink disabled="#{aktualiziraneNaSlujitel.page - 1 lt 0}"
							action="#{aktualiziraneNaSlujitel.setPage(aktualiziraneNaSlujitel.page - 1)}"
							value="&lt;&lt;" />

						<h:outputText value=" " />

						<!-- други страници -->
						<ui:repeat value="#{aktualiziraneNaSlujitel.pagesList}"
							var="currPage">
							<h:commandLink
								disabled="#{aktualiziraneNaSlujitel.getPage() eq currPage.intValue() - 1}"
								action="#{aktualiziraneNaSlujitel.setPage(currPage.intValue() - 1)}"
								value="#{currPage}" />

							<h:outputText value=" " />
						</ui:repeat>

						<!-- следваща страница -->
						<h:commandLink
							disabled="#{aktualiziraneNaSlujitel.page + 1 ge aktualiziraneNaSlujitel.pagesCount}"
							action="#{aktualiziraneNaSlujitel.setPage(aktualiziraneNaSlujitel.page + 1)}"
							value="&gt;&gt;" />

					</f:facet>

				</h:dataTable>
			</h:form>
		</div>

		<h:form>
			<table class="mainTable" style="margin-left: -20px;">
				<tr>
					<td><h:outputLabel value="Име*">
							<br />
							<h:inputText id="name" value="#{aktualiziraneNaSlujitel.name}"
								maxlength="50" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}" 
								validatorMessage="Въведеното име съдържа некоректни символи или е прекалено късо.">
								<f:validateRegex pattern="^[a-zA-Zа-яА-Я]{2,50}$" />
							</h:inputText>
							<br/>
							<h:message for="name" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Фамилия*">
							<br />
							<h:inputText id="family"
								value="#{aktualiziraneNaSlujitel.family}" maxlength="50"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}" 
								validatorMessage="Въведената фамилия съдържа некоректни символи или е прекалено къса.">
								<f:validateRegex pattern="^[a-zA-Zа-яА-Я]{2,50}$" />
							</h:inputText>
							<br/>
							<h:message for="family" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Град*">
							<br />
							<h:inputText id="city"
								value="#{aktualiziraneNaSlujitel.addressCity}" maxlength="30"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}" 
								validatorMessage="Въведеното населено място съдържа некоректни символи или е прекалено късо.">
								<f:validateRegex pattern="^[a-zA-Zа-яА-Я]{3,30}$" />
							</h:inputText>
							<br/>
							<h:message for="city" class="errorMsg" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Адрес*">
							<br />
							<h:inputText id="address"
								value="#{aktualiziraneNaSlujitel.addressLine}" maxlength="100"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}" 
								validatorMessage="Въведеният адрес е прекалено къс.">
								<f:validateRegex pattern="^.{5,100}$" />
							</h:inputText>
							<br/>
							<h:message for="address" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Електронна поща*">
							<br />
							<h:inputText id="mail" value="#{aktualiziraneNaSlujitel.mail}"
								maxlength="50" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}"
								validatorMessage="Електронната поща е невалидна. Пример: potrbitel@mail.bg">
								<f:validateRegex
									pattern="^[a-zA-Z][a-zA-Z0-9._%+-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$" />
							</h:inputText>
							<br/>
							<h:message for="mail" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Телефонен номер*">
							<br />
							<h:inputText id="phone"
								value="#{aktualiziraneNaSlujitel.phoneNumber}" maxlength="50"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaSlujitel.rowSelected}"
								validatorMessage="Телефонният номер е невалиден. Примери: +359885609456, 082860450">
								<f:validateRegex pattern="^[+]?[0-9]{6,14}$" />
							</h:inputText>
							<br/>
							<h:message for="phone" class="errorMsg" />
						</h:outputLabel></td>
				</tr>
				<tr>

					<td colspan="3">
						<!-- бутонът промени трябва да е в тази форма !!! --> <h:commandButton
							action="#{aktualiziraneNaSlujitel.writeIt()}" value="Промени"
							class="regButton"
							style="width:80px;height:40px;margin-left: 650px;"
							disabled="#{!aktualiziraneNaSlujitel.rowSelected or !aktualiziraneNaSlujitel.changingAllowed}" />
					</td>
				</tr>
			</table>

		</h:form>

		<h:form>
			<table class="buttonTable" style="margin-left: -20px;">
				<!-- формата е разделена на две, за да не се проверяват данните
			при натискането на бутоните "Отмени" и "Добави" -->
				<tr><td></td><td></td>
					<td><h:commandButton
							action="#{aktualiziraneNaSlujitel.deselectRow()}" value="Отмени"
							class="regButton" style="width:80px;height:40px;margin-left:554px;"
							disabled="#{!aktualiziraneNaSlujitel.rowSelected}" />
					<h:commandButton
							action="#{aktualiziraneNaSlujitel.goToAdd()}" value="Добави"
							class="regButton" style="width:80px;height:40px;"
							disabled="#{!aktualiziraneNaSlujitel.goToAddAllowed}" /></td>
				</tr>
				<tr>
					<td><h:outputText
							value="#{aktualiziraneNaSlujitel.errorMessage}" /></td>
				</tr>
			</table>
		</h:form>

	</ui:define>

</ui:composition>
</html>